import requests
import hashlib
import time
from urllib.parse import urlencode



def payurl(id,paytype,token):
    times = int(time.time() * 1000)

    print(times)

    json_data = {

        'id':id,
        'pay_type': paytype,
	      'return_url':'https://h5.newbee.net.cn/#/pages/userCenter/orderDetail?order_id=' + id,
        'timestamp': str(times),
    }

    query_string = 'pay/order/submit?' + urlencode(json_data) + '&key=6rnrdpjjv6wz2sspxqeibesov1itxddc'
    # print(query_string)
    lowstr = query_string.lower()
    sign = hashlib.md5(lowstr.encode()).hexdigest()
    # print(sign)

    headers = {
        'accept': '*/*',
        'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
        'cache-control': 'no-cache',
        'content-type': 'application/json;charset=UTF-8',
        'origin': 'https://h5.newbee.net.cn',
        'platformn': 'h5',
        'pragma': 'no-cache',
        'priority': 'u=1, i',
        'referer': 'https://h5.newbee.net.cn/',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-site',
        'signature': '2bd17b71495819c32b37b39388bcb2ac',
        'token': token,
        'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1',
        'x-token': sign,
    }

    response = requests.post('https://pay.newbee.net.cn/pay/order/submit', headers=headers, json=json_data)
    return response.json()


# getpayurl('38093500','497493e0-0e54-4f54-84d0-50ffd2387d50')